package EjemplosEventosBasicos;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


public class EjemploListSelectionListener {
	public void montarVentana (){
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		String[][] datos = new String[][]{{"Jesus","Damian","Rocio","Aroa"},{"Carlos","Rafael","Javi","Vanesa"},{"Norberto","Rafa","Carlos","Lucas"},{"Jose Luis","Ruben","Jesus","Alonso"}};
		String[] columnas = new String[]{"Columna uno","Columna dos","Columna tres","Columna cuatro"};
		JTable table = new JTable(datos, columnas);
		
		ListSelectionModel lsm = table.getSelectionModel();
		lsm.addListSelectionListener(new ListSelectionListener(){

			public void valueChanged(ListSelectionEvent e) {
				
				System.out.println("Event for indexes "
                        + e.getFirstIndex() + " - " + e.getLastIndex()
                        + "; isAdjusting is " + e.getValueIsAdjusting()
                        + "; selected indexes:");
			}
			
		});
		
		frame.add(table);
		frame.setVisible(true);
		frame.pack();
	}
	
	public static void main (String[] args){
		EjemploListSelectionListener elsl = new EjemploListSelectionListener();
		elsl.montarVentana();
	}
}
